package top.hcode.hoj.service.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nutz.lang.Strings;
import org.springframework.stereotype.Component;
import top.hcode.hoj.dao.{{properCase name}}Dao;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.{{properCase name}};

/**
 * @author orangej
 * @since {{today}}
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class Admin{{properCase name}}Service {
    private final {{properCase name}}Dao {{camelCase name}}Dao;

    public IPage<{{properCase name}}> get{{properCase name}}List(QuerySampleDTO querySampleDTO) {
        IPage<{{properCase name}}> pager = new Page<>(querySampleDTO.getCurrentPage(), querySampleDTO.getLimit());

        QueryWrapper<{{properCase name}}> query = new QueryWrapper<>();
        if (Strings.isNotBlank(querySampleDTO.getKeyword())) {
            query.like("title", querySampleDTO.getKeyword());
        }
        {{camelCase name}}Dao.page(pager, query);
        return pager;
    }

    public {{properCase name}} get{{properCase name}}(Long id) {
        return {{camelCase name}}Dao.getById(id);
    }

    public {{properCase name}} save{{properCase name}}({{properCase name}} {{camelCase name}}) {
        {{camelCase name}}Dao.saveOrUpdate({{camelCase name}});
        return {{camelCase name}};
    }

    public void delete{{properCase name}}(Long id) {
        {{camelCase name}}Dao.removeById(id);
    }
}
